package com.com.effectivejava.commonmethods.examples;

import java.util.*;

/**
 * Created by pankaj on 7/13/14.
 */
public class Client {

    static List<Student> buildStudent(){
        Student student = new Student();
        student.setId(1);
        student.setName("Sara");
        student.setFavorite(getSubject(0));

        Student student2 = new Student();
        student2.setId(2);
        student2.setName("Lucy");
        student2.setFavorite(getSubject(1));

        Student student3 = new Student();
        student3.setId(3);
        student3.setName("John");
        student3.setFavorite(getSubject(2));

        List<Student> list = new ArrayList<>();
        list.add(student);
        list.add(student2);
        list.add(student3);

        return list;
    }

    static Subject getSubject(int i){
        List<Subject> list  = new ArrayList<>();
        for(Subject s : buildSubject()){
            list.add(s);
        }
        return list.get(i);
    }

    static Iterable<Subject> buildSubject(){
        final Subject subject = new Subject();
        subject.setId(1);
        subject.setName("PL");

        final Subject subject2 = new Subject();
        subject2.setId(2);
        subject2.setName("CSA");

        final Subject subject3 = new Subject();
        subject3.setId(3);
        subject3.setName("APP");

        return new ArrayList<Subject>(){{
            add(subject);
            add(subject2);
            add(subject3);
        }};
    }

    public static void main(String[] args) {
        Set<Student> set  = new HashSet<>();
        set.addAll(buildStudent());
        for (Student student : set){
            System.out.println("student = " + student.hashCode());
            System.out.println("subject = " + student.getFavorite().hashCode());
        }
    }
}
